<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        
    </style>
</head>
<body>
    
</body>
<script>
    
    console.log( Number( 123 ) );

    console.log("--------")

    
    // 严格转换：不允许出现除空格外的非数字，出现了，就是NaN
    // 纯空格 和 空字符转成0
    // 数字中间有空格也是NaN
    
    console.log( Number( "123" ) );
    console.log( Number( "a123" ) );
    console.log( Number( "123b" ) );
    console.log( Number( " 123" ) );
    console.log( Number( "123 " ) );
    console.log( Number( "12 3" ) );
    console.log( Number( "1!23" ) );
    console.log( Number( "123abc" ) );
    console.log( Number( "123abc456" ) );
    console.log( Number( "123.456" ) );
    console.log( Number( "-123.456" ) );
    console.log( Number( "" ) );
    console.log( Number( "    " ) );
    
    console.log("--------")

    // true为1，false为0
    console.log( Number(true) )
    console.log( Number(false) )

    console.log("--------")
    
    // 花括号对象转成NaN
    // 中括号对象：空数组为0，有且只有一个数值型数据的数组，就是这个数值数据，其他都是NaN
    console.log( Number({}) )
    console.log( Number({name:"admin"}) )
    console.log( Number([]) )
    console.log( Number([34]) )
    console.log( Number([34,67]) )
    console.log( Number(["hello"]) )
    console.log( Number([true]) )
    console.log( Number([{}]) )

    console.log("--------")

    // 函数都是NaN
    console.log( Number(function(){}) )
    console.log( Number(function(){console.log(1)}) )

    console.log("--------")

    // undefined为NaN，null为0
    console.log(  Number(undefined) )
    console.log(  Number(null) )

    console.log("--------")

    // 空格和空字符都是NaN
    // 非严格转换
    // 其他字符从左向右依次转换，能转则转，不能转停止。第一位就不能转，直接NaN，不能识别小数点

    // parseInt()的规则，先将数据转成字符，再将字符转成数值

    console.log( parseInt( "hello" ) )
    console.log( parseInt( "365" ) )
    console.log( parseInt( "365.789" ) )
    console.log( parseInt( "36abc5" ) )
    console.log( parseInt( "abc365" ) )
    console.log( parseInt( "365abc" ) )
    console.log( parseInt( "" ) )
    console.log( parseInt( "   " ) )

    console.log( parseInt( true ) )
    console.log( parseInt( false ) )
    console.log( parseInt( function(){} ) )
    console.log( parseInt( {} ) )
    console.log( parseInt( [] ) )
    console.log( parseInt( [34] ) )
    console.log( parseInt( [34,56] ) )
    console.log( parseInt( [true] ) )
    console.log( parseInt( [{}] ) )

    console.log("---------")

    // 规则同parseInt，能识别小数点
    console.log( parseFloat("365.789") );
    console.log( parseFloat("365.7a89") );
    console.log( parseFloat("365.789a") );
    console.log( parseFloat("a365.789") );
    console.log( parseFloat("") );
    console.log( parseFloat("   ") );
    console.log( parseFloat({}) );
    console.log( parseFloat([]) );
    console.log( parseFloat([45]) );
    console.log( parseFloat([45,56]) );
    console.log( parseFloat([true,56]) );
    console.log( parseFloat([function(){}]) );
    console.log( parseFloat( undefined ) );
    console.log( parseFloat( null ) );

    console.log("---------")

    // 同Number的规则，四舍五入取整
    console.log( Math.round("365") )
    console.log( Math.round("365.789") )
    console.log( Math.round("365.78a9") )
    console.log( Math.round("365.789a") )
    console.log( Math.round("") )
    console.log( Math.round("   ") )
    console.log( Math.round(true) )
    console.log( Math.round(undefined) )
    console.log( Math.round(null) )
    console.log( Math.round({}) )
    console.log( Math.round([]) )
    console.log( Math.round([45.78]) )
    console.log( Math.round([45.78, 67]) )
    console.log( Math.round([true,7]) )
    console.log( Math.round(function(){}) )



</script>
</html>